package com.trajan.exercise.datastructure;

/*

   Created with IntelliJ IDEA.

   Ing. Tomáš Herich
   --------------------------- 
   19. 06. 2013
   10:34 AM

*/

public class HashCodeEqualsOverride {

    private int id;
    private String name;
    private String surname;

    public HashCodeEqualsOverride(int id, String name, String surname) {
        this.id = id;
        this.name = name;
        this.surname = surname;
    }

    @Override
    public boolean equals(Object obj) {

        if (obj == this) {
            return true;
        }

        if (obj == null && this.getClass() != obj.getClass()) {
            return false;
        }

        HashCodeEqualsOverride other = (HashCodeEqualsOverride) obj;

        return (id == other.id &&
                (name != null && name.equals(other.name)) &&
                (surname != null && surname.equals(other.surname)));

    }

    @Override
    public int hashCode() {

        int prime = 31;
        int result = 1;

        result = result * prime + id;
        result = result * prime + ((name == null) ? 0 : name.hashCode());
        result = result * prime + ((surname == null) ? 0 : surname.hashCode());

        return result;
    }
}
